/*
  Darts -- Double-ARray Trie System

  $Id: darts.cpp 1674 2008-03-22 11:21:34Z taku $;

  Copyright(C) 2001-2007 Taku Kudo <taku@chasen.org>
  All rights reserved.
*/
#include "darts.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <string>

int main22(int argc, char **argv) {
  if (argc < 3) {
    std::cerr << "Usage: " << argv[0] << " <Index File> <Test File>" << std::endl;
    return -1;
  }
 //argv[1] = "linux.words";
  Darts::DoubleArray da;
  std::string index = argv[argc-2];
  char * test = argv[argc-1];
  if (da.open(index.c_str())) {
    std::cerr << "Error: cannot open " << index << std::endl;
    return -1;
  }

  Darts::DoubleArray::result_pair_type  result_pair[1024];
  Darts::DoubleArray::key_type          key[1024];


/*  while (std::cin.getline(key, sizeof(key))) {
    size_t num = da.commonPrefixSearch(key, result_pair, sizeof(result_pair));
    if (num == 0) {
      std::cout << key << ": not found" << std::endl;
    } else {
      std::cout << key << ": found, num=" << num << " ";
      for (size_t i = 0; i < num; ++i) {
        std::cout << " " << result_pair[i].value
                  << ":" << result_pair[i].length;
      }
      std::cout << std::endl;
    }
  }
*/
  char * temp_str = (char *)calloc(1024,sizeof(char));
  FILE * fp = fopen(test,"r");

  if(fp==NULL){
	std::cout << "Test Word" <<std::endl;
	exit(0);
  }
	while(!feof(fp)){
		fscanf(fp,"%s\n",temp_str);
		size_t num = da.commonPrefixSearch(temp_str, result_pair, sizeof(result_pair));
    if (num == 0) {
      std::cout << temp_str << ": not found" << std::endl;
    } else {
      std::cout << temp_str << ": found, num=" << num << " ";
      for (size_t i = 0; i < num; ++i) {
        std::cout << " " << result_pair[i].value
                  << ":" << result_pair[i].length;
      }
      std::cout << std::endl;
    }
	}
 
  return 0;
}
